package com.yanfei.zero.apis;

import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yanfei.zero.infrastructure.mq.MqProducer;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@Tag(name="MQ相关")
@RestController
/**
 * 在RabbitMQ中，队列（Queue）和交换机（Exchange）之间的关系是通过绑定（Binding）来建立的。
 * 交换机负责接收消息并将它们路由到一个或多个队列中，而队列则负责存储这些消息，直到消费者消费它们
 */
public class MqController {
	@Resource
    @Lazy
	private MqProducer mqProducer;
	
	@Operation(summary = "发送消息")
    @GetMapping(path = "sendData")
    public void sendMsg(@RequestParam(name = "msg") String msg, @RequestParam(name = "routingKey") String routingKey) throws Exception {
		mqProducer.sendMsgByTopicExchange(msg, routingKey);
    }
	
	@Operation(summary = "发送TTL消息")
    @GetMapping(path = "sendTTLData")
    public void sendTTLMsg(@RequestParam(name = "msg") String msg, @RequestParam(name = "routingKey") String routingKey) throws Exception {
		mqProducer.sendExpireMsg(msg, routingKey);
    }
	
	@Operation(summary = "删除所有")
    @GetMapping(path = "delAll")
    public void delAll() throws Exception {
		mqProducer.deleteAllQueues();
    }
}
